<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态音乐播放器</title>
    <!-- Font Awesome 图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
            background-size: 400% 400%;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            color: white;
            animation: gradientBG 15s ease infinite;
            overflow: hidden;
        }

        @keyframes gradientBG {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }

        .music-container {
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 15px;
            box-shadow: 0 20px 20px rgba(0, 0, 0, 0.2);
            display: flex;
            padding: 20px 30px;
            position: relative;
            margin: 100px 0;
            z-index: 10;
            width: 400px;
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }

        .music-container:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 25px rgba(0, 0, 0, 0.3);
        }

        .img-container {
            position: relative;
            width: 110px;
        }

        .img-container::after {
            content: '';
            background-color: white;
            border-radius: 50%;
            position: absolute;
            bottom: 100%;
            left: 50%;
            width: 20px;
            height: 20px;
            transform: translate(-50%, 50%);
        }

        .img-container img {
            border-radius: 50%;
            object-fit: cover;
            height: 110px;
            width: 110px;
            position: absolute;
            bottom: 0;
            left: 0;
            animation: rotate 3s linear infinite;
            animation-play-state: paused;
            transition: all 0.3s ease;
            border: 2px solid rgba(255, 255, 255, 0.3);
        }

        .music-container.play .img-container img {
            animation-play-state: running;
            box-shadow: 0 0 20px rgba(255, 255, 255, 0.4);
        }

        @keyframes rotate {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        .navigation {
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1;
            margin-left: 20px;
        }

        .action-btn {
            background-color: transparent;
            border: 0;
            color: white;
            font-size: 20px;
            cursor: pointer;
            padding: 10px;
            margin: 0 15px;
            transition: all 0.2s ease;
        }

        .action-btn:hover {
            color: #23d5ab;
            transform: scale(1.1);
        }

        .action-btn.action-btn-big {
            font-size: 30px;
        }

        .action-btn:focus {
            outline: none;
        }

        .music-info {
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 15px 15px 0 0;
            position: absolute;
            top: 0;
            left: 20px;
            width: calc(100% - 40px);
            padding: 10px 10px 10px 150px;
            opacity: 0;
            transform: translateY(0%);
            transition: all 0.3s ease;
            z-index: 0;
            backdrop-filter: blur(5px);
        }

        .music-container.play .music-info {
            opacity: 1;
            transform: translateY(-100%);
        }

        .music-info h4 {
            margin: 0;
            font-size: 18px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .progress-container {
            background: rgba(255, 255, 255, 0.3);
            border-radius: 5px;
            cursor: pointer;
            margin: 10px 0;
            height: 4px;
            width: 100%;
            transition: height 0.2s ease;
        }

        .progress-container:hover {
            height: 6px;
        }

        .progress {
            background: linear-gradient(to right, #23a6d5, #23d5ab);
            border-radius: 5px;
            height: 100%;
            width: 0%;
            transition: width 0.1s linear;
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            .music-container {
                width: 90%;
                padding: 15px 20px;
                flex-direction: column;
                align-items: center;
            }
            
            .img-container {
                margin-bottom: 20px;
            }
            
            .navigation {
                margin-left: 0;
                margin-top: 20px;
            }
            
            .music-info {
                padding: 10px;
                text-align: center;
            }
        }

        /* 音乐文件链接区域 */
        .download-links {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background: rgba(255, 255, 255, 0.2);
            padding: 15px;
            border-radius: 10px;
            backdrop-filter: blur(5px);
        }

        .download-links h3 {
            margin-bottom: 10px;
            font-size: 16px;
        }

        .download-links a {
            color: white;
            text-decoration: none;
            display: block;
            margin: 5px 0;
            transition: color 0.2s;
        }

        .download-links a:hover {
            color: #23d5ab;
        }
    </style>
</head>
<body>
    <div class="music-container" id="music-container">
        <div class="music-info">
            <h4 id="title">歌曲加载中...</h4>
            <div class="progress-container" id="progress-container">
                <div class="progress" id="progress"></div>
            </div>
        </div>

        <audio src="" id="audio"></audio>

        <div class="img-container">
            <img src="https://picsum.photos/200" alt="音乐封面" id="cover">
        </div>

        <div class="navigation">
            <button id="prev" class="action-btn" title="上一首">
                <i class="fas fa-backward"></i>
            </button>
            <button id="play" class="action-btn action-btn-big" title="播放/暂停">
                <i class="fas fa-play"></i>
            </button>
            <button id="next" class="action-btn" title="下一首">
                <i class="fas fa-forward"></i>
            </button>
        </div>
    </div>

    <div class="download-links">
        <h3></h3>
        <a href="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" download></a>
        <a href="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3" download></a>
        <a href="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3" download></a>
    </div>

    <script>
        // 您提供的JavaScript代码
        // DOM元素
        const musicContainer = document.getElementById('music-container');
        const playBtn = document.getElementById('play');
        const prevBtn = document.getElementById('prev');
        const nextBtn = document.getElementById('next');
        const audio = document.getElementById('audio');
        const progress = document.getElementById('progress');
        const progressContainer = document.getElementById('progress-container');
        const title = document.getElementById('title');
        const cover = document.getElementById('cover');

        // 歌曲列表 - 使用在线示例音乐
        const songs = [
            { 
                name: 'SoundHelix Song 1', 
                audioSrc: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3',
                coverSrc: 'https://picsum.photos/200?random=1'
            },
            { 
                name: 'SoundHelix Song 2', 
                audioSrc: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3',
                coverSrc: 'https://picsum.photos/200?random=2'
            },
            { 
                name: 'SoundHelix Song 3', 
                audioSrc: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3',
                coverSrc: 'https://picsum.photos/200?random=3'
            }
        ];

        // 当前歌曲索引
        let songIndex = 0;

        // 初始化加载歌曲
        loadSong(songs[songIndex]);

        // 加载歌曲
        function loadSong(song) {
            title.innerText = song.name;
            audio.src = song.audioSrc;
            cover.src = song.coverSrc;
        }

        // 播放歌曲
        function playSong() {
            musicContainer.classList.add('play');
            playBtn.querySelector('i.fas').classList.remove('fa-play');
            playBtn.querySelector('i.fas').classList.add('fa-pause');
            audio.play();
        }

        // 暂停歌曲
        function pauseSong() {
            musicContainer.classList.remove('play');
            playBtn.querySelector('i.fas').classList.add('fa-play');
            playBtn.querySelector('i.fas').classList.remove('fa-pause');
            audio.pause();
        }

        // 上一首
        function prevSong() {
            songIndex--;
            if (songIndex < 0) {
                songIndex = songs.length - 1;
            }
            loadSong(songs[songIndex]);
            playSong();
        }

        // 下一首
        function nextSong() {
            songIndex++;
            if (songIndex > songs.length - 1) {
                songIndex = 0;
            }
            loadSong(songs[songIndex]);
            playSong();
        }

        // 更新进度条
        function updateProgress(e) {
            const { duration, currentTime } = e.srcElement;
            const progressPercent = (currentTime / duration) * 100;
            progress.style.width = `${progressPercent}%`;
        }

        // 设置进度条
        function setProgress(e) {
            const width = this.clientWidth;
            const clickX = e.offsetX;
            const duration = audio.duration;
            audio.currentTime = (clickX / width) * duration;
        }

        // 事件监听
        playBtn.addEventListener('click', () => {
            const isPlaying = musicContainer.classList.contains('play');
            if (isPlaying) {
                pauseSong();
            } else {
                playSong();
            }
        });

        // 切换歌曲
        prevBtn.addEventListener('click', prevSong);
        nextBtn.addEventListener('click', nextSong);

        // 进度条更新
        audio.addEventListener('timeupdate', updateProgress);

        // 点击进度条
        progressContainer.addEventListener('click', setProgress);

        // 歌曲结束自动下一首
        audio.addEventListener('ended', nextSong);
    </script>
</body>
</html>